<%@page import="com.fractalist.man.constants.ManConstants"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<%
	pageContext.setAttribute("commentStateMap",
			ManConstants.COMMENT_STATE_MAP);
	pageContext.setAttribute("articleTypeMap",
			ManConstants.ARTICLE_TYPE_MAP);
	pageContext.setAttribute("articlePublishTypeMap",
			ManConstants.ARTICLE_PUBLISHTYPE_MAP);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>评论列表</title>
<link rel="stylesheet" href="${ctx }/css/styles.css" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.6.1.min.js"></script>
<jsp:include page="/common/jscalendar.jsp"></jsp:include>
<style>
.tc a {
	color: red;
}
</style>
<script type="text/javascript">
	var userId = "${userId}";
	var articleTypeMap = {};
	<c:forEach items="${articleTypeMap}" var="entry">
	articleTypeMap["${entry.key}"] = "${entry.value}";
	</c:forEach>
	var pageNo = 1;
	var pageSize = 10;
	var pageCount = 0;

	$(function() {

		$("#table_wrapper").height($(window).height() - 40);

		//翻页
		$("#home").click(function() {
			if (pageNo != 1) {
				pageNo = 1;
				queryHandle(pageNo);
			}
		});
		$("#last").click(function() {
			if (pageNo != pageCount) {
				pageNo = pageCount;
				queryHandle(pageNo);
			}
		});
		$("#previous").click(function() {
			if (pageNo != 1) {
				pageNo--;
				queryHandle(pageNo);
			}
		});
		$("#next").click(function() {
			if (pageNo != pageCount) {
				pageNo++;
				queryHandle(pageNo);
			}
		});
		$("#jump").click(function() {
			var jumpValue = $("#currentPage").val();
			if (parseInt(jumpValue) > pageCount || parseInt(jumpValue) < 1) {
				alert("跳转页码输入有误！");
				return;
			}
			pageNo = parseInt(jumpValue);
			queryHandle(pageNo);
		});

		queryHandle(1);
	});

	var commentStateMap = {};
	<c:forEach items="${commentStateMap}" var="entry">
	commentStateMap["${entry.key}"] = "${entry.value}";
	</c:forEach>
	var userType = "${USERSESSION.groupId}";
	var commonTimeAlert = "请点击选择日期";

	function auditCommentOk(itemId) {
		$.post("${ctx}/manage/auditCommentOk.action", {
			commentId : itemId
		}, function(data) {
			alert("操作成功");
			location.href = "${ctx}/manager/viewCommentPage.action";
		});
	}

	function auditCommentFail(itemId) {
		$.post("${ctx}/manage/auditCommentFail.action", {
			commentId : itemId
		}, function(data) {
			alert("操作成功");
			location.href = "${ctx}/manager/viewCommentPage.action";
		});
	}

	function queryHandle(pageNo) {
		$("#listData").html("");
		var columnId = $("#columnId").val();
		var publishType = $("#publishType").val();
		$
				.post(
						"${ctx}/manager/mCommentPage.action?rnd="
								+ Math.random(),
						{
							pageNumber : pageNo,
							pageLine : pageSize,
							startDate : $("#startDate").val(),
							endDate : $("#endDate").val(),
							columnId : columnId,
							publishType : publishType
						},
						function(data) {
							data = eval("(" + data + ")");
							var allSize = data.totalCount;
							pageCount = Math.ceil(allSize / pageSize);
							$("#pageCount").html(pageCount);
							$("#allSize").html(allSize);
							$("#currentPage").val(pageNo);
							var listData = "";
							$
									.each(
											data.list,
											function(i, item) {
												var btnStr = "无";
												if (item.state == 0) {
													btnStr = "<a href='javascript:void(0);' onclick='auditCommentOk("
															+ item.id
															+ ")'>审核通过</a>&nbsp;"
															+ "<a href='javascript:void(0);' onclick='auditCommentFail("
															+ item.id
															+ ")'>审核不通过(删除)</a>&nbsp;";
												}
												listData += "<tr><td class='tc'>"
														+ articleTypeMap[item.columnId]
														+ "</td><td class='tc'>"
														+ item.name
														+ "</td><td class='tc'>"
														+ item.content
														+ "</td><td class='tc'>"
														+ commentStateMap[item.state]
														+ "</td><td class='tc'>"
														+ item.createDate
														+ "</td><td class='tc'>"
														+ btnStr + "</td></tr>";
											});
							$("#listData").html(listData);
						});
	}

	function notNull(obj) {
		return obj ? obj : '';
	}

	function nullRate(obj) {
		return obj ? obj + '%' : '';
	}
</script>
</head>
<body>
	<div id="wrapper">
		<div id="content_wrap">
			<div class="tabs_content">
				<div class="active_tab" id="tab1">
					<div class="toolbar2">
						模块：<select id="columnId" name="columnId">
							<option value="">请选择</option>
							<c:forEach items="${articleTypeMap}" var="entry">
								<option value="${entry.key }">${entry.value }</option>
							</c:forEach>
						</select>&nbsp; 发布者：<input id="publishType" />&nbsp; 创建日期：<input
							id="startDate" type="text" style="width: 80px"
							onclick="javascript:createPopCalendar(this.id);" />&nbsp;至&nbsp;<input
							id="endDate" type="text" style="width: 80px"
							onclick="javascript:createPopCalendar(this.id);" /> &nbsp; <a
							href="javascript:void(0);" onclick="queryHandle(1);"
							class="button">检索</a>&nbsp;
					</div>
					<div id="table_wrapper" style="width: 100%; overflow: auto;">
						<table class="table" cellpadding="0" cellspacing="0">
							<thead>
								<tr>
									<th><b>模块</b></th>
									<th><b>发布者</b></th>
									<th><b>内容</b></th>
									<th><b>状态</b></th>
									<th><b>创建日期</b></th>
									<th><b>操作</b></th>
								</tr>
							</thead>
							<tbody id="listData">
							</tbody>
							<tfoot>
								<tr>
									<td colspan="10" style="border: 0px; padding-top: 3px;"><a
										id="home" href="javascript:void(0);" class="button1">首页</a> <a
										id="previous" href="javascript:void(0);" class="button1">上一页</a>
										<a id="next" href="javascript:void(0);" class="button1">下一页</a>
										<a id="last" href="javascript:void(0);" class="button1">末页</a>
										&nbsp;&nbsp;&nbsp;第<input id="currentPage" type="text"
										style="width: 20px; text-align: center;" />页 <a id="jump"
										href="javascript:void(0);" class="button" style="width: 50px;">跳转</a>
										&nbsp;&nbsp;&nbsp;共<span id="pageCount"></span>页<span
										id="allSize"></span>条</td>
								</tr>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>

